package com.jvxb.manage.livable.service.impl;

import com.baomidou.mybatisplus.core.conditions.Condition;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jvxb.common.constants.DbConstants;
import com.jvxb.manage.livable.entity.WorkOrder;
import com.jvxb.manage.livable.service.DataAlertService;
import com.jvxb.manage.livable.service.WorkOrderService;
import com.jvxb.manage.livable.service.dataAlert.BaseDataAlertService;
import com.jvxb.manage.livable.vo.WorkOrderOperateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author jvxb
 * @since 2022-02-10
 */
@Service
public class DataAlertServiceImpl implements DataAlertService {

    @Autowired
    WorkOrderService workOrderService;
    @Autowired
    Map<String, BaseDataAlertService> dataAlertServiceMap;

    @Override
    public void executeOrder(WorkOrderOperateVo operateVo) {
        QueryWrapper wrapper = Condition.create().eq(WorkOrder.ID, operateVo.getId()).select(WorkOrder.DB_TYPE);
        WorkOrder workOrder = workOrderService.getOne(wrapper);
        dataAlertService(workOrder.getDbType()).executeOrder(operateVo);
    }

    private BaseDataAlertService dataAlertService(String dbType) {
        return dataAlertServiceMap.get(dbType + DbConstants.DATA_ALERT_SERVICE);
    }

}
